package com.weiqiao.report.distributior.rest;

import com.weiqiao.aop.log.Log;
import com.weiqiao.report.distributior.Service.IOrderReportService;
import com.weiqiao.report.distributior.domain.OrdersReportEntity;
import com.weiqiao.report.distributior.domain.dto.OrdersReportEntityDTO;
import com.weiqiao.utils.FileUtil;
import com.weiqiao.utils.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/report")
public class OrderReportController {
    @Autowired
    private IOrderReportService orderService;

    @Log("订单佣金列表")
    @GetMapping("/order-list")
    public ResponseEntity getOrderList(OrdersReportEntity vo, Pageable pageable) {
        List<OrdersReportEntityDTO> list = orderService.getOrderList(vo, pageable);
        int count = orderService.countNum(vo);
        return new ResponseEntity(PageUtil.toPage(list, count), HttpStatus.OK);
    }

    @Log("导出订单佣金列表")
    @GetMapping("/export-order-list")
    public void exportOrderList(OrdersReportEntity vo, HttpServletResponse response) throws IOException {
        List<Map<String, Object>> list = orderService.expportOrderList(vo);
        FileUtil.downloadExcel(list, response);
    }
}
